package com.example.demo.controller;

import com.example.demo.entity.vo.QuartzSosVO;
import com.example.demo.music.TtsMusicUtil;
import com.example.demo.quartz.scheduler.SchedulerUtil;
import com.example.demo.result.Result;
import com.example.demo.service.IQuartzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/*
 *
 *   @Author:max
 *   @Date: 2024/4/10-04-10-18:35
 *   定时任务框架
 */
@Slf4j
@Api(tags = "定时任务")
@RestController
@RequestMapping("/quartz")
public class QuartzController {

    @Autowired
    private TtsMusicUtil ttsMusicUtil;

    @Autowired
    private IQuartzService iQuartzService;

    @ApiOperation(value = "文字转语音播放地址")
    @GetMapping("/getMusicUrl")
    public Result getMusicUrl(String message){
        String url = ttsMusicUtil.syntheticAudio(message);
        return Result.success(url).msg("音频地址获取成功");
    }

    //SchedulerUtil 测试
    @ApiOperation(value = "SchedulerUtil测试")
    @GetMapping("/schedulerUtil")
    public Result schedulerUtil() throws SchedulerException {
        SchedulerUtil.addJob();
        return Result.success().msg("启动成功");
    }

    //接口控制任务的开始或停止
    @ApiOperation(value = "接口控制任务的开始或停止")
    @PostMapping("/startOrStop")
    public Result startOrStop(@Valid @RequestBody QuartzSosVO quartzSosVO) throws ClassNotFoundException {
        log.info("我进入Controller了");
        iQuartzService.startOrStop(quartzSosVO);
        return Result.success().msg("接口控制任务的开始或停止成功");
    }
}
